package com.xy.servicemanage.controller;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.servicemanage.ServiceShow;
import com.ruoyi.common.core.domain.servicemanage.dto.ServiceQueryCondition;
import com.ruoyi.common.core.domain.servicemanage.dto.ServiceTreeNode;
import com.xy.servicemanage.service.IServiceShowService;
import com.xy.servicemanage.service.IServiceTreeService;
import com.xy.servicemanage.service.impl.ServiceTreeServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;

import javax.annotation.Resource;

/**
 * 服务显示信息Controller
 *
 * @author ruoyi
 * @date 2025-06-05
 */
@RestController
@RequestMapping("/show")
public class ServiceShowController extends BaseController
{
    @Autowired
    private IServiceShowService serviceShowService;

    /**
     * 获取服务显示信息详细信息
     */
//    @RequiresPermissions("servicemanage:show:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(serviceShowService.selectServiceShowById(id));
    }

    /**
     * 新增服务显示信息
     */
    @RequiresPermissions("servicemanage:show:add")
    @Log(title = "服务显示信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ServiceShow serviceShow)
    {
        return toAjax(serviceShowService.insertServiceShow(serviceShow));
    }

    /**
     * 修改服务显示信息
     */
    @RequiresPermissions("servicemanage:show:edit")
    @Log(title = "服务显示信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ServiceShow serviceShow)
    {
        return toAjax(serviceShowService.updateServiceShow(serviceShow));
    }

    /**
     * 删除服务显示信息
     */
    @RequiresPermissions("servicemanage:show:delete")
    @Log(title = "服务显示信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public AjaxResult deleteLogic(@PathVariable Long id, @RequestParam int deleted) {
        int start = deleted == 1 ? 0 : 1;
        try {
            return toAjax(serviceShowService.deleteServiceShowById(id, start));
        } catch (Exception e) {
            return AjaxResult.error("删除失败：" + e.getMessage());
        }
    }



    @Autowired
    private IServiceTreeService serviceTreeService;

    /**
     * 获取完整的服务树形结构
     */
//    @RequiresPermissions("servicemanage:show:list1")
    @GetMapping("/list1")
    public AjaxResult getFullServiceTree(ServiceQueryCondition condition) {
        List<ServiceTreeNode> tree = serviceTreeService.getFullServiceTree(condition);
        return AjaxResult.success(tree);
    }

    /**
     * 新增：获取服务项目详情
     */
    @GetMapping(value = "/detail/{serviceId}")
    public AjaxResult getDetail(@PathVariable("serviceId") Long serviceId)
    {
        return success(serviceShowService.getServiceDetailById(serviceId));
    }
}
